﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using SocialIn.Core.Data;
using System.Data;

namespace SocialIn.Biz
{
    public sealed class GiveAndTake
    {
        ConnectionStringSettings _BaseDBCon = null;

        public GiveAndTake()
        {
            _BaseDBCon = ConfigurationManager.ConnectionStrings[ConfigName.DBConfig];
        }

        public Result<DataTable> SearchHelpRequest(string userID, string year, string month)
        {
            Result<DataTable> resultValue = null;

            string query = String.Format(@"SELECT help.Seq, help.NgoID, help.TalentID, help.Title, RTRIM(CONVERT(char, help.WishStartDate, 112)) AS RequestDate, code.CodeName, help.WishStartDate, help.WishEndDate  FROM HelpRequest help
                    INNER JOIN CodeMaster code
                    ON help.TalentID = code.SubCategory
                    INNER JOIN NGO ngo
                    ON help.NgoID = ngo.NgoID
                    WHERE ngo.PersonInChargeID = '{0}'
                    AND
                    SUBSTRING(CONVERT(char, getdate(), 112), 0, 7) = '{1}'", userID, year + ((month.Length == 1) ? "0" + month : month));

            SqlHelper sql = new SqlHelper(_BaseDBCon.ProviderName, _BaseDBCon.ConnectionString);
            resultValue = sql.ExecuteDataTable(query, null);

            return resultValue;
        }
    }
}